﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;
using AudioPlayer.GUI.Renderer;
using AudioPlayer.GUI.Music;
using AudioPlayer.Database;
using AudioPlayer.Plugin.Storage;
namespace AudioPlayer {
	public partial class MainForm : Form {
		#region Constructor
		public MainForm() {
			InitializeComponent();
			if (!this.DesignMode) {
				this.AllowDrop = true;
				//this.mainTool.Renderer = new ToolRenderer();
				this.mainMenu.Renderer = new MenuRenderer();
				this.SetDefaultImages();
			}
		}
		#endregion
		#region Events
		protected override void OnMouseWheel(MouseEventArgs e) {
			if (listControl1.Bounds.Contains(e.Location)) {
				listControl1.MouseWheel(e);
			}
		}
        protected override void OnDragEnter(DragEventArgs drgevent) {
			Point p = this.PointToClient(MousePosition);
			if (listControl1.Bounds.Contains(p)) {
				listControl1.DragDropEnter(drgevent);
			} else {
				//drgevent.Effect = DragDropEffects.None;
			}
        }
        protected override void OnDragOver(DragEventArgs drgevent) {
			Point p = this.PointToClient(MousePosition);
			if (listControl1.Bounds.Contains(p)) {
				listControl1.DragDropOver(drgevent);
			} else {
				//drgevent.Effect = DragDropEffects.None;
			}
        }
        protected override void OnDragDrop(DragEventArgs drgevent) {
			Point p = this.PointToClient(MousePosition);
			if (listControl1.Bounds.Contains(p)) {
				listControl1.DragDropDone(drgevent);
			} else {
				//drgevent.Effect = DragDropEffects.None;
			}
		}
		#endregion

		#region Debug stuff
		private void SetDefaultImages() {
			//TODO: Update later to more smarter function.
			
			//this.toolBack.Image = Config.Images.PlayerRew;
			//this.toolNext.Image = Config.Images.PlayerFwd;
			//this.toolPlay.Image = Config.Images.PlayerPlay;
		}

		private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
			this.Close();
		}

		private void addMusicToolStripMenuItem_Click(object sender, EventArgs e) {
			FolderBrowserDialog fd = new FolderBrowserDialog();
			if (fd.ShowDialog() == DialogResult.OK) {
				Config.Library.Scan(fd.SelectedPath);
			}
		}

		#endregion

		#region Tool Items
		/// <summary>
		/// Handles the Click event of the toolPlay control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
		private void toolPlay_Click(object sender, EventArgs e) {
			if (Config.Plugins.HasPlayControl) {
				Config.Plugins.PlayControl.Play();
			}
		}

		/// <summary>
		/// Handles the Click event of the toolBack control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
		private void toolBack_Click(object sender, EventArgs e) {
			if (Config.Plugins.HasPlayControl) {
				Config.Plugins.PlayControl.Prev();
			}
		}

		/// <summary>
		/// Handles the Click event of the toolNext control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
		private void toolNext_Click(object sender, EventArgs e) {
			if (Config.Plugins.HasPlayControl) {
				Config.Plugins.PlayControl.Next();
			}
		}
		#endregion

		#region Property
		internal MusicTree MusicTree {
			get { return this.musicTree1; }
			set { musicTree1 = value; }
		}
		internal AudioPlayer.GUI.List.ListControl ListControl {
			get { return listControl1; }
			set { listControl1 = value; }
		}
		#endregion
	}
}
